import {Injectable} from '@angular/core';
import {LoginAdmin} from "../api/LoginAdmin";

@Injectable({
  providedIn: 'root'
})
export class JWTService {

  constructor(private loginAdmin: LoginAdmin) {
  }

  setHeaders(request: XMLHttpRequest) {
    if (this.loginAdmin.isLogin) {
      request.setRequestHeader('Authorization-Manage', this.loginAdmin.jwt);
    }
  }

  openWindow(url: string) {
    if (url.indexOf('?') < 0) {
      url += '?';
    }
    window.open(url + '&Authorization-Manage=' + this.loginAdmin.jwt, 'blank');
  }

}
